package uy.edu.um.ltic.server.business;

import java.util.ArrayList;

import uy.edu.um.ltic.commons.EmployeeVO;
import uy.edu.um.ltic.exception.DataBaseException;
import uy.edu.um.ltic.server.persistence.EmployeeDAOFactory;

public class EmployeeMgr implements EmployeeMgt {

	private static EmployeeMgr instance = null;

	private EmployeeMgr() {
	}

	public static EmployeeMgr getInstance() {
		if (instance == null) {
			instance = new EmployeeMgr();
		}
		return instance;
	}

	@Override
	public void addEmployee(EmployeeVO oEmployee) throws DataBaseException { // Se pasa una instance del
													// Employee?
		EmployeeDAOFactory
				.getInstance()
				.getEmployeeDAOMgt()
				.addEmployee(
						new Employee(oEmployee.getName(), oEmployee
								.getSurname(), oEmployee.getDocument(),
								oEmployee.getnEmployee(), oEmployee
										.getPositionInCompany(), oEmployee
										.getCurrentCountry(), oEmployee
										.getBranch(),
								oEmployee.getDepartment(), oEmployee
										.getUsername(),
								oEmployee.getPassword(), oEmployee
										.getDocumentType(), oEmployee
										.getImage(), oEmployee
										.getAvailability(), oEmployee
										.getEmail(), oEmployee
										.isAdministrator(), oEmployee.getSalt()));
	}

	@Override
	public void deleteEmployee(int nEmployee) throws DataBaseException {
		EmployeeDAOFactory.getInstance().getEmployeeDAOMgt()
				.deleteEmployee(nEmployee);
	}

	@Override
	public void editEmployee(EmployeeVO oEmployee) throws DataBaseException {
		EmployeeDAOFactory.getInstance().getEmployeeDAOMgt().editEmployee(new Employee(oEmployee));
	}

	@Override
	public ArrayList<Employee> getEmployees(EmployeeVO oEmployee)  throws DataBaseException{ 
		return EmployeeDAOFactory
				.getInstance()
				.getEmployeeDAOMgt()
				.getEmployees(
						new Employee(oEmployee.getName(), oEmployee
								.getSurname(), oEmployee.getDocument(),
								oEmployee.getnEmployee(), oEmployee
										.getPositionInCompany(), oEmployee
										.getCurrentCountry(), oEmployee
										.getBranch(),
								oEmployee.getDepartment(), oEmployee
										.getUsername(),
								oEmployee.getPassword(), oEmployee
										.getDocumentType(), oEmployee
										.getImage(), oEmployee
										.getAvailability(), oEmployee
										.getEmail(), oEmployee
										.isAdministrator(), oEmployee.getSalt()));
	}

	@Override
	public Employee getEmployeeLogIn(String username) throws DataBaseException {
		return EmployeeDAOFactory.getInstance().getEmployeeDAOMgt()
				.getEmployeeLogIn(username);
	}

	@Override
	public void setStatus(String status, int nEmployee) throws DataBaseException {
		EmployeeDAOFactory.getInstance().getEmployeeDAOMgt()
		.setStatus(nEmployee, status);
	}

	@Override
	public Employee getEmployeeNEmp(int nEmployee) throws DataBaseException {
		return  EmployeeDAOFactory.getInstance().getEmployeeDAOMgt().getEmployeeNEmp(nEmployee);
	}

	@Override
	public ArrayList<Employee> getAllEmployees() throws DataBaseException {
		return EmployeeDAOFactory.getInstance().getEmployeeDAOMgt().getAllEmployees();
	}

}
